package com.toman.Adpter;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.toman.Entity.Production_Entity;
import com.toman.R;

import java.util.ArrayList;

/**
 * Created by  GridView_adpter on Administrator on 2017/11/3 on 16:13.
 */

public class Production_adpter extends BaseAdapter {

    //上下文对象
    Context context;
    ArrayList<Production_Entity> arrayList;
    LayoutInflater inflater;

    public Production_adpter(Context context, ArrayList<Production_Entity> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return arrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        AddPackage addPackage;
        if (null == convertView) {
            addPackage = new AddPackage();

            convertView = inflater.inflate(R.layout.production_, null, false);
            addPackage.title = (TextView) convertView.findViewById(R.id.mProductionTitle);
            addPackage.content = (TextView) convertView.findViewById(R.id.mProductionContent);

            convertView.setTag(addPackage);
        } else {
            addPackage = (AddPackage) convertView.getTag();
        }

        addPackage.title.setText(arrayList.get(position).getName());
        if (arrayList.get(position).getAuthorise() == 1) {
            addPackage.content.setText("已授权");
        } else {
            addPackage.content.setText("未授权");
        }

        return convertView;
    }


    public class AddPackage {
        TextView title;
        TextView content;
    }


    /*
        提示删除
     */
    public void DelDialog(final Integer position) {
        final AlertDialog dialog = new AlertDialog.Builder(context).create();
        dialog.show();
        dialog.getWindow().setContentView(R.layout.del_layout2);

        dialog.getWindow().findViewById(R.id.mDetermine).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "" + position, Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });

    }


}
